require 'test/unit'
require 'semantictext/document' 

class TestExport < Test::Unit::TestCase

	def test_end_to_end_loading
		unit = SemanticText::Document.new
		unit.parse_from(ENV['SANDBOX']+'/semantictext/testfiles/complex.art')
    actual = unit.export_html
    actual = actual.split /\n/
    
    expected_file=File.new(ENV['SANDBOX']+'/semantictext/testfiles/regression-exportsample.txt')
    expected = expected_file.readlines

    (0..(expected.size-1)).each {|index| assert_equal expected[index],actual[index]+"\n"}
    
    assert_equal expected.size, actual.size
  end
  
  def test_escaping_paragraphs
    unit = SemanticText::Document.new
    unit.parse ''
    unit.parse 'escaping test < > &'
    
    assert_equal "\n<p> escaping test &lt; &gt; &amp;</p>\n", unit.export_html
  end
  
  def test_escaping_headings
    unit = SemanticText::Document.new
    unit.parse ''
    unit.parse '!heading < > &'
    
    assert_equal "\n<h1>heading &lt; &gt; &amp;</h1>\n", unit.export_html
  end
  
  def test_escaping_bullet_points
    unit = SemanticText::Document.new
    unit.parse ''
    unit.parse '* < > &'

    assert_equal "\n\t<ul><li> &lt; &gt; &amp;</li>\n\t</ul>\n", unit.export_html
  end
  
  def test_escaping_link
    unit = SemanticText::Document.new
    unit.parse ''
    unit.parse 'http://www.example.com/app?name1=value1&name2=value2'

    assert_equal "\n<p><a href=\"http://www.example.com/app?name1=value1&name2=value2\">http://www.example.com/app?name1=value1&amp;name2=value2</a></p>\n", unit.export_html
  end
  
end
